package algotithm.leetcode.dp.hot.test279;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/9-22:05
 * @Title 279. 完全平方数
 * @URL https://leetcode-cn.com/problems/perfect-squares/
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int n = 12;
        int s = solution.numSquares(n);
        System.out.println(s);
    }

    public int numSquares(int n) {
        int[] dp = new int[n+1];
        for (int i = 1; i <= n; i++) {
            dp[i] = i;
            for (int j = 1; i - j * j >= 0; j++) {
                dp[i] = Math.min(dp[i],dp[i-j*j] + 1);
            }
        }
        return dp[n];
    }

}
